package org.mathig.poker.table;

import org.mathig.poker.Card;
import org.mathig.poker.Color;
import org.mathig.poker.Rank;
import org.mathig.poker.util.RandomUtils;

/**
 * A poker deck of 52 cards (4 colors * 13 ranks).
 * 
 * @author mathig
 */
public class Deck {

	private Card[] cards = new Card[52];

	private int nextCardIndex;

	public Deck() {
		int i = 0;
		for (Color color : Color.values()) {
			for (Rank rank : Rank.values()) {
				cards[i++] = new Card(rank, color);
			}
		}
	}

	public void shuffle() {
		RandomUtils.shuffle(cards);
		nextCardIndex = 0;
	}

	public Card next() {
		if (nextCardIndex < cards.length)
			return cards[nextCardIndex++];
		throw new NullPointerException("no more cards in the deck ! try to shuffle");
	}

	public Card[] getCards() {
		return cards;
	}

	public void setCards(Card[] cards) {
		this.cards = cards;
	}

}
